import request from '@/utils/request'


export function getWechatUserInfo(code) {
  return request({
    url: '/wechat/userInfo',
    headers: {
      isToken: false
    },
    method: 'get',
    params: { code }
  });
}

export function wechatLogin(userInfo) {
  return request({
    url: '/wechat/login',
    headers: {
      isToken: false
    },
    method: 'post',
    data: userInfo
  });
}

// 微信支付相关接口

/**
 * 创建支付订单
 * @param {Object} payRequest 支付请求参数
 * @param {number} payRequest.totalAmount 支付金额（分）
 * @returns {Promise} 支付参数
 */
export function createPayOrder(payRequest) {
  return request({
    url: '/wechat/pay/create',
    method: 'post',
    data: payRequest
  });
}

/**
 * 申请退款
 * @param {Object} refundRequest 退款请求参数
 * @param {string} refundRequest.outTradeNo 原商户订单号
 * @param {number} refundRequest.refundAmount 退款金额（分）
 * @returns {Promise} 退款结果
 */
export function createRefund(refundRequest) {
  return request({
    url: '/wechat/pay/refund',
    method: 'post',
    data: refundRequest
  });
}

/**
 * 查询退款状态
 * @param {string} outRefundNo 退款单号
 * @returns {Promise} 退款状态
 */
export function queryRefund(outRefundNo) {
  return request({
    url: `/wechat/pay/refund/query/${outRefundNo}`,
    method: 'get'
  });
}

/**
 * 获取微信JSSDK配置
 * @param {string} url 当前页面URL
 * @returns {Promise} JSSDK配置参数
 */
export function getJSSDKConfig(url) {
  return request({
    url: '/wechat/pay/jssdk/config',
    method: 'get',
    params: { url }
  });
}